/**
 * Created by tang on 2018/5/29.
 */
import React, { Component } from 'react';
import { connect } from 'dva';
import { Card, Badge, Table, Divider, Button ,Tabs,Form,Col,Row,Input,List,Avatar,Icon,Popconfirm} from 'antd';
import PageHeaderLayout from '@/layouts/PageHeaderLayout';
import DescriptionList from '../../components/DescriptionList';
import styles from './BannerInfo.less';
import queryString from 'query-string';
const TabPane = Tabs.TabPane;
import placeImg from '../../assets/icon_default.png';
const FormItem = Form.Item;
//权限
import { checks } from '../../utils/authority';

const { Description } = DescriptionList;

@connect(state => ({
  banner: state.banner,
}))
@Form.create()

export default class BannerInfo extends Component {

//数据初始化
  state = {
    pageSize: 5, //页数
    showLoadMore: true,
    loadingMore: false,
  };

  componentDidMount() {
    const { pageSize } = this.state;
    const { dispatch } = this.props;
    dispatch({
      type: 'banner/clear',
    });

    var search = queryString.parse(this.props.location.search);
    if (search.id){
      dispatch({
        type: 'banner/info',
        payload: {
          id: search.id,
          pageSize: pageSize,
        }
      });


      this.setState({
        pageSize: pageSize,
      })
    }


  }

  render() {
    const { banner } = this.props;
    const {img,type,sort,url,content, id} = banner;
    var des = [];
    var type1 = '';
    if(type == 0){
      type1 = '无连接';
    }else if(type == 1){
      type1 = '内链';
    }else {
      type1 = "外链";
      des.push(
        <Description term="外链">{url}</Description>
      )
    }

    return (
      <PageHeaderLayout
        title={"轮播图详情"}
      >
        <Card>

          <Card bordered={false}>
            <DescriptionList size="large" style={{ marginBottom: 32 }}>
              <Description term="类型">{type1 + ""}</Description>
              <Description term="排序">{sort + ""}</Description>

              {des}
            </DescriptionList>
            <Divider style={{ marginBottom: 32 }} />
            <DescriptionList size="large" title="图片" style={{ marginBottom: 32 }}>
              <img className={styles.image_div} src={img} />
            </DescriptionList>
            <Divider style={{ marginBottom: 32 }} />
            {
              type == 1?
                <DescriptionList size="large" title="内容" style={{ marginBottom: 32 }}>
                  <div><span dangerouslySetInnerHTML={{ __html: content }}></span></div>
                </DescriptionList>
                :
                ''
            }

          </Card>
        </Card>

      </PageHeaderLayout>
    );
  }
}
